import { createRouter, createWebHashHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue'

const routes = [{
  path: "/login",
  name: 'login',
  component: () => import("../views/LoginView.vue")
},
{
  path: "/admin-index",
  name: "admin-index",
  component: () => import("../views/AdminIndexView.vue"),
  children: [
    {
      path: "/user",
      name: "user",
      component: () => import("../views/UserView.vue"),
      children: [
        {
          path: "/system",
          name: "system",
          component: () => import("../views/com/System.vue"),
          children: [
            {
              path: "/system/user",
              name: "userfrom",
              component: () => import("../views/com/UserFrom.vue")
            },
            {
              path: "/system/rol",
              name: "rol",
              component: () => import("../views/com/Rol.vue")
            }, {
              path: "/system/menu",
              name: "menu",
              component: () => import("../views/com/Menu.vue")
            },
            {
              path: "/system/payOrderList",
              name: "payOrderList",
              component: () => import("../views/com/payOrderList.vue")
            },
            {
              path: "/system/couponList",
              name: "couponList",
              component: () => import("../views/com/couponList.vue")
            },
            {
              path: "/system/Notice",
              name: "Notice",
              component: () => import("../views/com/Notice.vue")
            },
            {
              path: "/system/orderList",
              name: "orderList",
              component: () => import("../views/com/orderList.vue")
            },
            {
              path: "/system/goodsList",
              name: "orderLgoodsListist",
              component: () => import("../views/com/goodsList.vue"),
              // children:[
              //   {
              //     path: "/system/addList",
              //     name: "addList",
              //     component: () => import("../views/com/addList.vue")
              //   },
              // ]
            },
            {
              path: "/system/addList",
              name: "addList",
              component: () => import("../views/com/addList.vue")
            },

          ]
        },

      ],
    }, {
      path: "/index",
      name: "index",
      component: () => import("../views/Index.vue")
    },


  ]
},

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from) => {
  console.log(to, from);
  if (to.path == "/login"  ) {
    return true
  }if(to.path == "/"){
    router.push("/login")
  }else {
    let token = localStorage.token
    let ouTime = localStorage.token_outTime
    let now = Date.now()
    if (now > ouTime || !token) {
      router.push("/login")
    } else {

      return true
    }
  }

})

export default router
